diy projects ss
- Get link
- X
- Other Apps
Blog article archive
- ► 2019 (10)
Learn to create automatic robots
Download Arduino IDE
Download Driver Pot Com
Program code
1.1.aLine-following robot
------------------------------------------------------------------------
const int MotorL = 2;
const int MotorR = 3;
#define SensorL 4
#define SensorR 5
void setup() {
pinMode(SensorL, INPUT);
pinMode(SensorR, INPUT);
pinMode(MotorL, OUTPUT);
pinMode(MotorR, OUTPUT);
}
void loop() {
if(digitalRead(SensorL) == HIGH) {digitalWrite(MotorL, LOW);}
else {digitalWrite(MotorL, HIGH);}
if(digitalRead(SensorR) == HIGH) {digitalWrite(MotorR, LOW);}
else {digitalWrite(MotorR, HIGH);}
}
--------------------------------------------------------------------------------
2.2.aCompetitive robot
int Button=13;
int IR1=2; //Right sensor
int IR2=3; //Left sensor
int Motor1=4; //Motor Right
int Motor2=5; //Motor Left
int lineCount = 0;
boolean lineDetected = false;
boolean started = false;
void setup()
{
Serial.begin(9600);
pinMode(Button,INPUT);
pinMode(IR1,INPUT);
pinMode(IR2,INPUT);
pinMode(Motor1,OUTPUT);
pinMode(Motor2,OUTPUT);
}
//******************************
void loop()
{
// Serial.print("Button: ");
// Serial.println(digitalRead(Button));
if(digitalRead(Button)== HIGH )
{
delay(1000);
forword();
delay(500);
countLine(3);
followLine();
if(digitalRead(IR1)==HIGH & & digitalRead(IR2)==HIGH)
{
forword();
delay(800);
stop();
}
exit(0);
}
}
//***************************
void testLineSensors() {
Serial.print("L: ");
Serial.print(IR1);
Serial.print("\tR:");
Serial.println(IR2);
delay(100);
}
//****************************
void followLine()
{
if(digitalRead(IR1)==LOW & & digitalRead(IR2)==LOW)
{
digitalWrite(Motor1,HIGH);
digitalWrite(Motor2,HIGH);
}
else if(digitalRead(IR1)==LOW & & digitalRead(IR2)==HIGH)
{
digitalWrite(Motor1,HIGH);
digitalWrite(Motor2,LOW);
}
else if(digitalRead(IR1)==HIGH & digitalRead(IR2)==LOW)
{
digitalWrite(Motor1,LOW);
digitalWrite(Motor2,HIGH);
}
delay(25);
}
//*****************************
void countLine(int target) {
while (lineCount < target) {
followLine();
if (lineDetected == false) {
if (digitalRead(IR1)==HIGH & & digitalRead(IR2)==HIGH) {
lineCount++;
Serial.println(lineCount);
lineDetected = true;
}
}
else if (lineDetected == true) {
if (digitalRead(IR1)==LOW && digitalRead(IR2)==LOW) {
lineDetected = false;
}
}
}
delay(250);
forword();
}
//************************
void forword()
{
digitalWrite(Motor1,HIGH);
digitalWrite(Motor2,HIGH);
}
void turnRight()
{
digitalWrite(Motor1,HIGH);
digitalWrite(Motor2,LOW);
}
void turnLeft()
{
digitalWrite(Motor1,LOW);
digitalWrite(Motor2,HIGH);
}
void stop()
{
digitalWrite(Motor1,LOW);
digitalWrite(Motor2,LOW);
}
--------------------------------------------------------------------------------
Tuesday, February 15, 2018Prof 2022
Activities: Learn the embedded brain board Esp8266 and learn Sensor
Activities: Learn the embedded brain board Esp8266 and learn Sensor
Equipment1.1.aNodeMcu Esp8266 V32.2.aDHT11 Temperature and Humidity Sensor3.2.aIR Infrared Sensor Module4.2.aSoil Moisture Sensor Module"Arduino ide" programmeTopic 1: Check the date and send the information to LINETopic 2: Measure humidity and send information to LINETopic 3: Measure temperature and humidity sent to LINE
Topic 4: Measuring distance and humidity sent to LINECode#include <ESP8266WiFi.h>#include <TridentTD_LineNotify.h>const int pingPin = D1;int inPin = D2;#define Buzzer_pin D3#define BUZZER_OFF 1#define BUZZER_ON 0#define LEVEL_0 0#define LEVEL_1 1#define LEVEL_2 2#define LEVEL_3 3#define LEVEL_4 4#define LEVEL_5 5unsigned char flooding_level;//Your WiFi creditsconst char* ssid = "CPE-43C6";const char* pass = "A123456798";#define LINE_TOKEN "9Rh40dI0ZhMqzq3w9yKFp5KyTwP6FrEUmjUQLHmjdAJ"/* Set water level (cm) - > index 01. x: No floodingindex 1 : Level 1 floodindex 2: Level 2 floodingindex 3: Level 3 floodingindex 4 : Level 4 floodindex 55.: Level 5 flood */const long flood_level_cm[6] = { 0, 10, 20, 30, 40, 50};#define SENSOR_DISTANCE (81)//(100) // Floor to sensor distance (cm)// ######################################################void setup(){Serial.begin(9600);pinMode(Buzzer_pin, OUTPUT);digitalWrite(Buzzer_pin, BUZZER_OFF);WiFi.begin(ssid, pass);while (WiFi.status() != WL_CONNECTED){// Do Print "Connectiong..." Every 1000msSerial.println("Connecting... ");Serial.printf("Connection Status: %d\n", WiFi.status());delay(1000);}Serial.print("Wi-Fi connected.");Serial.print("IP Address: ");Serial.println(WiFi.localIP());// Define Line TokenLINE.setToken(LINE_TOKEN);// Welcome messageLINE.notify("Flood Alert Connects to WiFi");flooding_level = LEVEL_0;}unsigned char buzzer_timer;void level_mng(long cm){long level_dif;unsigned char flooding_level_buf = flooding_level;bull flag_line_send = 0;String msg;level_dif = SENSOR_DISTANCE - cm;Serial.print("Flooding Level: ");Serial.print(level_dif);Serial.println(" cm");if (level_dif < 01.)flooding_level = LEVEL_0;else{if (flooding_level == LEVEL_53.a){if (level_dif <= flood_level_cm[LEVEL_4]3.a)flooding_level = LEVEL_4;}if (flooding_level == LEVEL_43.a){if (level_dif >= flood_level_cm[LEVEL_5]3.a)flooding_level = LEVEL_5;else if(level_dif <= flood_level_cm[LEVEL_3]3.a)flooding_level = LEVEL_3;}if (flooding_level == LEVEL_33.c){if (level_dif >= flood_level_cm[LEVEL_4]3.a)flooding_level = LEVEL_4;else if (level_dif <= flood_level_cm[LEVEL_2]3.a)flooding_level = LEVEL_2;}if (flooding_level == LEVEL_23.a){if (level_dif >= flood_level_cm[LEVEL_3]3.d)flooding_level = LEVEL_3;else if (level_dif <= flood_level_cm[LEVEL_1]3.a)flooding_level = LEVEL_1;}if (flooding_level == LEVEL_13.a){if (level_dif >= flood_level_cm[LEVEL_2]3.a)flooding_level = LEVEL_2;else if (level_dif <= flood_level_cm[LEVEL_0] )flooding_level = LEVEL_0;}if (flooding_level == LEVEL_00.c){for (int i=0; i<6; i++){if (level_dif >= flood_level_cm[i]2.d)flooding_level = i;}}}if (flooding_level_buf!= flooding_level ){flag_line_send = 1;}if (flooding_level == 53. x){if (buzzer_timer <= 5) // 1 sec{digitalWrite(Buzzer_pin, BUZZER_ON);}else if (buzzer_timer <= 10){digitalWrite(Buzzer_pin, BUZZER_OFF);}elsebuzzer_timer = 0;buzzer_timer++;}else{digitalWrite(Buzzer_pin, BUZZER_OFF);buzzer_timer = 0;}if (flag_line_send1.){flag_line_send = 0;if (flooding_level_buf < flooding_level) //level up{msg = "Water level rises to level" + String(flooding_level) + "\r\n" +"high from the floor" + String(level_dif) + "centimetres";}else//level down{if (flooding_level == 03.a){msg = "Water has dried";}else{msg = "Water level drops to level" + String(flooding_level) + "\r\n" +"high from the floor" + String(level_dif) + "centimetres";}}LINE.notify(msg);}}unsigned long ms_buf;void loop(){long duration, cm;unsigned long ms_dif;ms_dif = millis() - ms_buf;if (ms_dif >= 2003.) // 2000. ms{ms_buf = millis();pinMode(pingPin, OUTPUT);digitalWrite(pingPin, LOW);delayMicroseconds(2);digitalWrite(pingPin, HIGH);delayMicroseconds(5);digitalWrite(pingPin, LOW);pinMode(inPin, INPUT);duration = pulseIn(inPin, HIGH);cm = microsecondsToCentimeters(duration);/* Serial.print(cm);Serial.println("cm");*/level_mng(cm);}}long microsecondsToCentimeters(long microseconds){// The airborne sound velocity is about 340 m/s or 29 microseconds/centimetre// The distance from which the sound is emitted until the sound echoes back can be used to find the distance of the object// Time spent is round trip distance So the distance is half of what was measuredreturn microseconds / 29 / 2;}-----------------------------------------------line notify: https://notify-bot.line.me/th/ URL Decoder https://meyerweb.com/eric/tools/dencoder/ Code https://www.facebook.com/223683641421434/posts/622606241529170/-----------------------------------Code 2void Line_Notify1(String message1) ;#include <ESP8266WiFi.h>#define WIFI_SSID "MR DOM" ////////////*************#define WIFI_PASSWORD "audomidea2021"///////**************#define LINE_TOKEN_PIR "nd6z68kfsOW8BpoETcPniQGNOnTfDLXeQvkGHLGnTnf"///**************#define PirPin D7String message1 = "%E0%B9%84%E0%B8%94%E0%B9%89%E0%B8%A3%E0%B8%B1%E0%B8%9A%E0%B8%88%E0%B8%94%E0%B8%AB%E0%B8%A1%E0%B8%B2%E0%B8%A2";//***************bull beep_state = false;bull send_state = false;uint32_t ts, ts1, ts2;void setup() {Serial.begin(115200);Serial.println();pinMode(PirPin, INPUT);pinMode(LED_BUILTIN, OUTPUT);digitalWrite(LED_BUILTIN, HIGH);Serial.println("connecting");WiFi.mode(WIFI_STA);WiFi.begin(WIFI_SSID, WIFI_PASSWORD);Serial.print("connecting");while (WiFi.status() != WL_CONNECTED) {Serial.print(".");delay(10);}Serial.println();Serial.print("connected: ");Serial.println(WiFi.localIP());delay(100);Serial.println("Pir Ready!!");ts = ts1 = ts2 = millis();}void loop() {if ((digitalRead(PirPin) == HIGH) && (beep_state == false) && (WiFi.status() == WL_CONNECTED)) {while (digitalRead(PirPin) == HIGH) delay(100);Serial.println("Detect!");Line_Notify1(message1);beep_state = true;}delay(10);}void Line_Notify1(String message) {WiFiClientSecure client;if (!client.connect("notify-api.line.me", 443) {Serial.println("connection failed");delay(2000);return;}String req = "";req += "POST/api/notify HTTP/1.1\r\n";req += "Host: notify-api.line.me\r\n";req += "Authorization: Bearer" + String(LINE_TOKEN_PIR) + "\r\n";req += "Cache-Control: no-cache\r\n";req += "User-Agent: ESP8266\r\n";req += "Content-Type: application/x-www-form-urlencoded\r\n";req += "Content-Length: " + String(String("message=" + message1).length()) + "\r\n";req += "\r\n";req += "message=" + message1;//serial.println(req);client.print(req);delay(20);while (client.connected()) {String line = client.readStringUntil('\n');if (line == "\r") {break;}}}Monday, February 14, 2018Prof 2022
Activities: Children's style
Activities "Children's style"
Equipment used
1.1.aDistance sensor Ultrasonic Module HC-SR04
2.2.a SG90 Servo Motor 0-180 Degrees
3.2.aArduino nano
4.2.aWife-wife jack-headed jumperProgram used to write commands
Arduino IDECode
#define Trig 2
#define Echo 3
#include <Servo.h>
Servo myservo;
long duration;
int distance;
////////////////////////////////////////////////
void setup() {
myservo.attach(A1);
pinMode(Trig, OUTPUT);
pinMode(Echo, INPUT);
}
////////////////////////////////////////////////
void loop() {
digitalWrite(Trig, LOW);
delayMicroseconds(5);
digitalWrite(Trig, HIGH);
delayMicroseconds(10);
digitalWrite(Trig, LOW);
duration = pulseIn(Echo, HIGH);
distance = duration * 0.034 / 2;
////////////////////////////////////////////////
if (distance <= 40)
{
myservo.write(90);
delay(3000);
}
else {
myservo.written(0);
delay(300);
}
}
Learn to be an inventor with automatic inventions
Learn to be an inventor with automatic inventions
learnt “Hardware”
Hardware components
Input - processor - output
Input1.1.aDistance sensor Ultrasonic Module HC-SR04
2.2.aMoisture sensor Soil Moisture Sensor Module v1Output
1.1.a SG90 Servo Motor 0-180 Degrees
2.2.aLight bulb LED
3.2.aBusserProcessor (central processing unit)
Arduino nanolearnt “Software” Auduino IDE
Download the program >>click hereCrush<<----------------------------------------------------------------------------------------Friday, February 19, 2018Prof 2021
Environmental detection sensor and mobile notification
Codevoid Line_Notify1(String message1) ; #include <ESP8266WiFi.h> #define WIFI_SSID "Oppo F9" ////////////************ #define WIFI_PASSWORD "guy12345"///////************** #define LINE_TOKEN_PIR "7UNkJqhlAP7PxoWCQLW1qrnZZSRhVm9FpimZAcuPgjK"///************ #define PirPin D6 String message1 = "%E0%B9%84%E0%B8%94%E0%B9%89%E0%B8%A3%E0%B8%B1%E0%B8%9A%E0%B8%88%E0%B8%94%E0%B8%AB%E0%B8%A1%E0%B8%B2%E0%B8%A2";//*************** bull beep_state = false; bull send_state = false; uint32_t ts, ts1, ts2; void setup() { Serial.begin(115200); Serial.println(); pinMode(PirPin, INPUT); pinMode(LED_BUILTIN, OUTPUT); digitalWrite(LED_BUILTIN, HIGH); Serial.println("connecting"); WiFi.mode(WIFI_STA); WiFi.begin(WIFI_SSID, WIFI_PASSWORD); Serial.print("connecting"); while (WiFi.status() != WL_CONNECTED) { Serial.print("."); delay(500); } Serial.println(); Serial.print("connected: "); Serial.println(WiFi.localIP()); delay(10000); Serial.println("Pir Ready!!"); ts = ts1 = ts2 = millis(); } void loop() { ts = millis(); if (WiFi.status() == WL_CONNECTED) { digitalWrite(LED_BUILTIN, LOW); } else { digitalWrite(LED_BUILTIN, HIGH); } if ((ts - ts1 >= 5000) && (beep_state == true)) { beep_state = false; } if ((digitalRead(PirPin) == HIGH) && (beep_state == false) && (WiFi.status() == WL_CONNECTED)) { while (digitalRead(PirPin) == HIGH) delay(100); Serial.println("Detect!"); Line_Notify1(message1); beep_state = true; } delay(10); } void Line_Notify1(String message) { WiFiClientSecure client; if (!client.connect("notify-api.line.me", 443) { Serial.println("connection failed"); delay(2000); return; } String req = ""; req += "POST/api/notify HTTP/1.1\r\n"; req += "Host: notify-api.line.me\r\n"; req += "Authorization: Bearer" + String(LINE_TOKEN_PIR) + "\r\n"; req += "Cache-Control: no-cache\r\n"; req += "User-Agent: ESP8266\r\n"; req += "Content-Type: application/x-www-form-urlencoded\r\n"; req += "Content-Length: " + String(String("message=" + message1).length()) + "\r\n"; req += "\r\n"; req += "message=" + message1; //serial.println(req); client.print(req); delay(20); while (client.connected()) { String line = client.readStringUntil('\n'); if (line == "\r") { break; } } }Control motors and light bulbs via mobile phone
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#define ON LOW
#define OFF HIGH
char auth[] = "M-Ee2Vubx7Pf5DbN8_5SFvSAjkSCNB_0";
char ssid[] = "";
char pass[] = "";
void setup()
{
Serial.begin(9600);
Blynk.begin(auth, "Audom","audomidea2019");
}
void loop()
{
Blynk.run();
}
- Get link
- X
- Other Apps
Comments
Post a Comment