Good day
I am a real novice and interested in learning. I have spent lots of time trying to integrate my sketch with various sleep methods from the net, but have not been successful and thought you might be able to help. using (SLEEP_MODE_PWR_DOWN)
Basically my project uses a touch sensor to turn a servo motor from 0 to 180 and back to zero.
Most of the time there is no activity and the arduino nano and servo motor kill my batteries after a few days. Sensor may only be touched once every few days if that.
So putting the arduino to sleep will help and then I need to figure out how to use a logic level mosfet to cut power to the Servo SG90 until the touch sensor is touched.
What arduino pins connect to the gate, drain , and source and do i need any resistors to the Gate or a pull down resistor?
Here is my code
#include <Servo.h>
// constants won't change
const int SENSOR = 2; // Arduino pin connected to motion sensor's pin 7
const int SERVO = 9; // Arduino pin connected to servo motor's pin 9
Servo servo; // create servo object to control a servo
int pos = 0; // variable to store the servo position
// variables will change:
int lastMotionState; // the previous state of motion sensor
int currentMotionState; // the current state of motion sensor
void setup() {
Serial.begin(9600); // initialize serial
pinMode(SENSOR, INPUT); // set arduino pin 9 to input mode
servo.attach(SERVO); // attaches the servo on pin 12 to the servo object
servo.write(0);
currentMotionState = digitalRead(SENSOR);
}
void loop() {
lastMotionState = currentMotionState; // save the last state
currentMotionState = digitalRead(SENSOR); // read new state
if (currentMotionState == LOW && lastMotionState == HIGH) { // pin state change: LOW -> HIGH
Serial.println("OFF");
servo.write(0);
delay(100); // waits (X)ms for the servo to reach the position
}
else
if (currentMotionState == HIGH && lastMotionState == LOW) { // pin state change: HIGH -> LOW
Serial.println("ACTIVE");
servo.write(180);
delay(2000); // waits (x)ms for the servo to reach the position
}
delay(10); // repeats program - larger delay - trigger is
}
I would have liked to show my wiring diagram but not quite sure how to do it
Your help would be greatly appreciated. I have been trying to figure this out for months now. Your comments are greatly appreciated
Best Regards,
Anthony