2

I am trying to make an automated watering system using an Arduino.

Here is my wiring diagram: Wiring Diagram And here is my circuit wired up: Photo of wired circuit

Here is the code that I'm using with Arduino. The code seems alright and the wiring on the Arduino seems okay as well, but I don't know where to place a speaker on the Arduino. The biggest problem is that the program doesn't run like I coded. After I uploaded this code to Arduino, the water pump just keeps running forever. Can anyone check up my code to make this run properly?

/**automated watering program **/
#include <avr/sleep.h>
#include <avr/wdt.h>
#define BEAT 300 // define time for the tone.
#define PINNO 12
int led = 13;
void setup() {
 // setup code to run once:
 pinMode(led, OUTPUT);
}
void loop() {
 // main code here, to run repeatedly:
 tone(PINNO,262,BEAT); // C(do)
 delay(BEAT);
 tone(PINNO,294,BEAT); // D(re)
 delay(BEAT);
 tone(PINNO,330,BEAT); // E(mi)
 delay(BEAT);
 tone(PINNO,262,BEAT); // C (do)
 delay(BEAT);
 tone(PINNO,294,BEAT); // D(re)
 delay(BEAT);
 tone(PINNO,330,BEAT); // E(mi)
 delay(BEAT);
 tone(PINNO,392,BEAT); // G(so)
 delay(BEAT);
 tone(PINNO,330,BEAT); // E(mi)
 delay(BEAT);
 tone(PINNO,294,BEAT); // D(re)
 delay(BEAT);
 tone(PINNO,262,BEAT); // C(do)
 delay(BEAT);
 tone(PINNO,294,BEAT); // D(re)
 delay(BEAT);
 tone(PINNO,330,BEAT); // E(mi)
 delay(BEAT);
 tone(PINNO,294,BEAT); // D(re)
 delay(BEAT);
 delay(1000); // Wait for 1 second
 digitalWrite(led,HIGH); //Make No. 11pin output HIGH = 5V
 delay(500); // Watering time
 digitalWrite(led,LOW); //Make No.11 pin output LOW = 0V
 // Shut down program to save battery using by watchdogtimer 24h standby mode
 int var = 0;
 while(var < 10800) {
 delayWDT(9); // 9seconds of shutdown
 var++; // 10800times repeat =24h
 }
}
void delayWDT(unsigned long t) {
 // delay excute while using powerdown mode
 delayWDT_setup(t); // watchdog timer setting
 ADCSRA &= ~(1 << ADEN); // ADEN bit clear and stop ADC
 set_sleep_mode(SLEEP_MODE_PWR_DOWN); // Powerdow mode
 sleep_enable();
 sleep_mode(); // sleep mode
 sleep_disable(); // WatchDog Timer times up and start working again
 ADCSRA |= (1 << ADEN); // turn on the ADC
}
void delayWDT_setup(unsigned int ii) {
 // setting up timer
 // 0=16ms, 1=32ms, 2=64ms, 3=128ms, 4=250ms, 5=500ms
 // 6=1sec, 7=2sec, 8=4sec, 9=8sec
 byte bb;
 if (ii > 9 ) {
 // get rid of strange numbers
 ii = 9;
 }
 bb =ii & 7;
 if (ii > 7) {
 bb |= (1 << 5);
 }
 bb |= ( 1 << WDCE );
 MCUSR &= ~(1 << WDRF); // MCU Status Reg. Watchdog Reset Flag ->0
 // start timed sequence
 WDTCSR |= (1 << WDCE) | (1<<WDE); // allow to edit watchdog
 // set new watchdog timeout value
 WDTCSR = bb;
 WDTCSR |= _BV(WDIE);
}
ISR(WDT_vect) {
 // the work after time up, WDT
 // wdt_cycle++;
}
sa_leinad
3,2182 gold badges23 silver badges51 bronze badges
asked Dec 30, 2016 at 12:14
7
  • 1
    Maybe if you try controlling pin 11, where the pump is connected, and not pin 13, it may help. Also I can't understand your wiring there (but it looks wrong - there are components missing). Please provide a schematic (which you can do using the schematic editor available when you edit your question). Commented Dec 30, 2016 at 12:18
  • 1
    As for where to place a speaker - how about pin 12, like you have already decided in your code? Commented Dec 30, 2016 at 12:26
  • Thank you, I uploaded a diagram i wire them exactly like the diagram. Commented Dec 30, 2016 at 15:06
  • What model transistor is that? Commented Dec 30, 2016 at 15:07
  • it says BC5478, It came with Arduino Starter Kit. Commented Dec 30, 2016 at 15:11

1 Answer 1

2

Problems with your setup:

  • Your pump is connected to pin 11 but you are controlling pin 13 (int led = 13;)
  • You have an LED in line with your transistor base. That should be a resistor, and the LED should be in parallel with the base (with its own resistor).
  • Your transistor is wired wrong. According to the datasheet the pins are C-B-E as viewed from the angle in your wiring diagram. You have the Arduino connected to E instead of B, the pump connected to B instead of C, and ground connected to C instead of E.
  • You don't have a flyback diode across the motor.

schematic

simulate this circuit – Schematic created using CircuitLab

answered Dec 30, 2016 at 15:40
3
  • Why does it need the resistors ?? Commented Jan 2, 2017 at 5:31
  • i tired this but didnt work Commented Jan 2, 2017 at 5:32
  • this time, speaker worked but the pump didnt work Commented Jan 2, 2017 at 5:32

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.