![]() ![]() The signal pin is typically yellow or orange and should be connected to PWM pin on the board. The ground wire is typically black or brown and should be connected to a ground pin on the board. The power wire is typically red, and should be connected to the 5V pin on the Arduino board. Servo motors have three wires: power, ground, and signal. You can also visit the Servo GitHub repository to learn more about this library. The second example sweeps the shaft of a RC servo motor back and forth across 180 degrees. ![]() The first example controls the position of a RC (hobby) servo motor with your Arduino and a potentiometer. In this article, you will find two easy examples that can be used by any Arduino board. If ((myRTC.minutes >= start_curfew) & (myRTC.The Servo Library is a great library for controlling servo motors. PinMode(leave, INPUT) // reed switch for red led PinMode(entry, INPUT) // reed switch for green led PinMode(NRSTPD, OUTPUT) // Set digital pin 5, Not Reset and Power-down //tag (I know there is room for improvement but if it works I can live with that for now.) #include I will work through the rest of the code and hope no issues. I am very happy with the solution you advised and thanks again. If I start with the exit code, red led, no problem 4 second delay. After that no problem, it works every time for both green and red led code. The first time the switches are operated for the entry code the green led comes on but no delay and the servo operates straight away. It seems to work fine except for the entry led (green) part of the code. I have added a 4 second delay to allow the flap to settle. I did as you said and tried it on a breadboard with push button switches. If((myRTC.minutes >= start_curfew) & (myRTC.minutes 3) Myservo.write(0) //back to 0 degrees //servo PinMode(leave,INPUT) // reed switch for red led PinMode(entry,INPUT) // reed switch for green led PinMode(NRSTPD, OUTPUT) // Set digital pin 10, Not Reset and Power-down //tag PinMode(activation, OUTPUT) // Set digital pin 10 as OUTPUT to connect it to the RFID /ENABLE pinĭigitalWrite(activation, LOW) // Activate the RFID reader Serial.begin(9600) // RFID reader SOUT pin connected to Serial RX pin at 9600bps //universal Int lastButtonState = 0 //last state of entry cct Int lastButtonState1 = 0 //last state of leave cct led cktĬonst int leave = A1 // monitor ckt for red led, normally low, goes high when reed 2 switch activate. #define MAX_LEN 16 //Maximum length of the arrayĬonst int entry = A0 // monitor ckt for green led, normally low, goes high when reed 1 switch activate. Unsigned char serNumA //4 bytes tag serial number, the first 5 bytes for the checksum byte Servo myservo //create servo object to control a servoĪddicoreRFID myRFID //AddicoreRFID object to control the RFID module I will look into that advice Robin2 thanks myservo.attach(9) //attachs the servo on pin 9 to servo object Myservo.write(90) //goes to 90 degrees and open doorĭigitalWrite(petfeeder,HIGH) //goes to Pet feeder hardware ckt Myservo.attach(9) //attachs the servo on pin 9 to servo object I thought to save power I could get servo to go to close position and then detach. It is added in at the end of the led_ckt code. My problem is as the code shows once the count has reached four it does light the appropriate led but I cant get the servo to move to close the flap. Whichever counter reaches four first will indicate whether the pet is entering or leaving the house and will light a green or red led to alert owner the direction the pet has taken. the pet pushes through the flap and as flap swings back and forth until it settles in vertical position it will have activated reed switches on either side of the flap and this will have incremented two counters. Have now put complete code together but have issue with servo motor.īasically when pet approaches pet flap rfid reads tag on pet, if access granted servo moves to 90 degrees position to open lock on flap. Have the project nearly built and all code individually tested all ok. Trying to build automatic pet flap and feeder. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |