I am powering solenoid with 24 volt as required however I am using TIP122
transistor that has base connected to Arduino Digital Pin 6 via a 1K Resistor. And the collector is connected to negative side of 1N4001 diode, this also serves as the Negative out for solenoid. and emitter is connected to the 24 volt power input. The positive input from power source is connected to positive terminal of diode is directly connected to solenoid.
As per the logic I am trying to turn on Solenoid based on Signal from Arduino PIN 6, but for some reason Solenoid doesnt power up.
In my code below I want to turn on solenoid if soil moisture goes above 60. the signal is coming from Pin 6 but solenoid doesnt power up.
#include <SPI.h>
int solenoidPin = 6; //This is the output pin on the Arduino we are using
int GLED = 5; // Wet Soil Indicator at Digital PIN D5
int RLED = 9; // Dry Soil Indicator at Digital PIN D9
int SENSE = 1; // Soil Sensor input at Analog PIN A1
int val = 0;
int greenLedPin = 2; // LED on pin 2
int yellowLedPin = 3;
int redLedPin = 4;
int lightSensorPin = A0;
int analogValue = 0;
void setup() {
pinMode(solenoidPin, OUTPUT); //Sets the pin as an output
// Open serial communications and wait for port to open:
Serial.begin(9600);
pinMode(greenLedPin, OUTPUT); // LED on pin 2
pinMode(yellowLedPin, OUTPUT);
pinMode(redLedPin, OUTPUT);
pinMode(GLED, OUTPUT);
pinMode(RLED, OUTPUT);
}
void loop() {
val = analogRead(SENSE);
val = val / 10;
analogValue = analogRead(lightSensorPin);
Serial.print("LDR value: ");
Serial.print(analogValue);
digitalWrite (redLedPin, analogValue < 55) ;
digitalWrite (yellowLedPin, analogValue >= 55 && analogValue <= 100) ;
digitalWrite (greenLedPin, analogValue > 100) ;
Serial.print(" Soil Moisture: ");
Serial.println(val);
digitalWrite(GLED, (val < 50));
digitalWrite(RLED, (val > 50));
// Turn on Solenoid Valve if soil moisture value greater than 60
digitalWrite(solenoidPin, (val > 60));
}
I am doubting on the diode to use , because I am powering solenoid of 24 volt and not sure if the diode is correct , as per my knowledge, diode can get direct if higher voltage is passed.
Any help will be greatly appreciated.