/*
void setup() {
pinMode(6, OUTPUT);
Serial.begin(9600);
}
void loop() {
int pot_value = analogRead(A0);
//if A0 = 0 V ADC 0
//if A0 = 5 ADC 1027
//this is N bit ADC 5 - 2^N-1
int angle = map(pot_value, 0, 1027,0, 270);
int Intensity = map(pot_value, 0,1027,0, 255);
Serial.print("A0 value:");
Serial.print(pot_value);
Serial.print(" Angle: ");
Serial.print(angle);
Serial.print(" Intensity: ");
Serial.print(Intensity);
analogWrite(6, Intensity);
}
*/
/*
void setup()
{
// put your setup code here, to run once:
pinMode(6, OUTPUT);
Serial.begin(9600);
}
void loop()
{
int pot_value = analogRead(A0);
//------------------At the analog input termional -----------
// if A0=0 V ADC 0
// if A0=5 V ADC 1027
// this is 10 bit ADC 5 = 2^{10}-1
// this is N bit ADC 5 = 2^N-1
//------------------At the Digital out termional (PWM) -----------
// if D6=0 V PWM value 0
// if D6=5 V PWM value 255
int angle = map(pot_value, 0, 1027, 0, 270);
int voltage = map(pot_value, 0, 1027, 0, 5);
int Intensity = map(pot_value, 0, 1027, 0, 255);
Serial.print("A0 value:");
Serial.print(pot_value);
Serial.print(" Voltage:");
Serial.print(voltage);
Serial.print(" Angle: ");
Serial.print(angle);
Serial.print(" Intensity : ");
Serial.println(Intensity);
analogWrite(6, Intensity);
}
*/
/*
##########
using servo
*/
/*
#include <Servo.h>
Servo myservo;
void setup()
{
// put your setup code here, to run once:
pinMode(6, OUTPUT);
Serial.begin(9600);
}
void loop()
{
int pot_value = analogRead(A0);
//------------------At the analog input termional -----------
// map(value, fromLow, fromHigh, toLow, toHigh)
int angle = map(pot_value, 0, 1027, 0, 270);
int voltage = map(pot_value, 0, 1027, 0, 5);
int Servo_angle_pwm = map(pot_value, 0, 1027, 0, 255);
int Servo_angle = map(pot_value, 0, 1027, 0, 180);
Serial.print("Input A0 value:");
Serial.print(pot_value);
Serial.print(" Input Voltage:");
Serial.print(voltage);
Serial.print(" Pot_Angle: ");
Serial.print(angle);
Serial.print(" Servo_angle_pwm : ");
Serial.println(Servo_angle_pwm);
Serial.print(" Servo_angle : ");
Serial.println(Servo_angle);
analogWrite(6, Servo_angle_pwm);
delay(2000);
//myservo.write(Servo_angle);
}
*/
//using motion sensor and servo
#include <Servo.h> // Include the Servo library to control a servo motor
int servoPin = 11; // Define the pin number (11) where the servo motor is connected
Servo servo1; // Create a Servo object to control the servo motor
void setup()
{
// This function runs once when the microcontroller starts
pinMode(12, INPUT); // Set pin 12 as an input (used for motion sensor input)
pinMode(7, OUTPUT); // Set pin 7 as an output (used to control an LED or another device)
servo1.attach(servoPin); // Attach the servo motor to the pin defined by servoPin (pin 11)
Serial.begin(9600); // Start serial communication at a baud rate of 9600 for debugging
}
void loop()
{
// This function runs continuously in a loop
int motion = digitalRead(12); // Read the input from the motion sensor connected to pin 12
// Check if motion is detected (motion sensor output is HIGH)
if (motion == HIGH)
{
servo1.write(90); // Move the servo motor to 90 degrees (middle position)
Serial.println("MOTION DETECTED"); // Print a message to the serial monitor
digitalWrite(7, HIGH); // Turn on the LED (or other device) connected to pin 7
delay(5000); // Wait for 5 seconds (5000 milliseconds)
}
else // If no motion is detected (motion sensor output is LOW)
{
servo1.write(0); // Move the servo motor back to 0 degrees (starting position)
Serial.println("NO MOTION DETECTED"); // Print a message to the serial monitor
digitalWrite(7, LOW); // Turn off the LED (or other device) connected to pin 7
delay(5000); // Wait for 5 seconds (5000 milliseconds)
}
}