Hallo, ich bin dotal neu im Bereich Arduino.
Vielleicht könnt ihr mir helfen.
Ich habe ein Projekt begonnen mit dem NodeMCU und einem Servomotor,
das alles habe ich auch zu laufen gebracht.
Nun wollte ich das gleiche Projekt aber mit einem DC Motor machen.
Ich weiss aber nicht wie ich das machen soll.
Bei YouTube komme ich auch nicht weiter.
Hier die Beschreibung:
Hier der Code:
// DIY Simple Single Axis Solar Tracker using RTC and Blynk App By Solarduino
// Note Summary
// Note : Safety is very important when dealing with electricity. We take no responsibilities while you do it at your own risk.
// Note : This Code is for single axis solar tracker using mathematical calculation and local time for sun tracking.
// Note : This System requires continuous internet access to Blynk App for Real Time Tracking.
// Note : This project does not require photo sensor for solar tracking.
// Note : The value shown in Blynk app / Serial monitor is refreshed every minute.
// Note : All credit shall be given to Solarduino.
// Note : Blog page for this code : DIY Simple Single Axis Solar Tracker using Real Time Clock and Blynk App replacing Photo sensors – A blog about DIY solar and arduino projects
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/
/* 1- Blynk Server and Wifi Connection */
#include <ESP8266WiFi.h> /* Enable the use of wifi module. Make sure you downloaded and installed the ESP8266 library*/
#include <BlynkSimpleEsp8266.h> /* Code for talking with Blynk*/
char auth[] = "9S_PDg7qQ_Jmw_4Sr0q_-AYYy0U3nRbz"; // Put in the Auth Token for the project from Blynk. You should receive it in your email.
char ssid[] = "apple-wifi"; // Key in your wifi name. You can check with your smart phone for your wifi name
char pass[] = "Dg9bande"; // Key in your wifi password.
#include <TimeLib.h> /* Program code related to Real Time Clock (RTC). */
#include <WidgetRTC.h> /* Communication code with Blynk Real Time Clock Widget */
BlynkTimer timer; /* Define parameter for Blynk Timer */
WidgetRTC rtc; /* Define parameter for RTC Widget */
/* 2- Servo Motor */
#include <Servo.h> /* Servo Library, came with Arduino IED software*/
Servo servo; /* Define variable for the Servo Motor */
int angleFinal = 90; /* Define variable as final angle for Servo Motor*/
float angle = 0 ; /* Define variable for Sun Path Angle, positive towards East and negative towards West*/
float angleAdd = 0; /* Define variable for minute angle difference. By default 15 degree for 1 hour change or 0.25 degree for 1 minute*/
int lockMechanism = 0; /* A safety feature to prevent overlapping code during tracking mounting*/
/* 3- Display refresh*/
unsigned long startMillis; /* start counting time for display refresh*/
unsigned long currentMillis; /* current counting time for display refresh */
const unsigned long period = 60000; // refresh every X seconds (in seconds) Default 60000 = 1 minute
/* 4- Callibration */
int offsetAngle = 65.55; // Key in hour angle based on your longitude & time zone on 1st January at 7am
// Refer to website : http://andrewmarsh.com/apps/releases/sunpath2d.html
void setup()
{
/* 0 - General */
Serial.begin(9600); /* Initiate the Serial Monitor function /
pinMode(16,OUTPUT); / Declare the Output Pin D4 (GPIO 2) as an output pin for LED Light*/
Serial.println("Angle = 90 Degree is at horrizontal, 0 degree is facing West, 180 degree is facing East");
Serial.println("angleFinal = 0 Degree is facing East, 90 degree is at Horrizontal, 180 degree is facing West");
/* 1- Blynk Server and Wifi Connection */
setSyncInterval(1); /* Synchronise or read time from the Blynk Server every 1 second /
Blynk.begin(auth,ssid,pass); / Initiate the Blynk server login for the specific project*/
while (Blynk.connect() == false ) {} /* If the Blynk Server not yet connected to nodeMCU, keep waiting here /
setSyncInterval(60); / After successful login, change Synchornise Time reading for every 10 minute (Do not need to always check for the time)*/
/* 2- Servo Motor */
servo.attach(16); // digital pin 0 for GPIO 16
servo.write(angleFinal); /* During startup set rotation to horrizontal*/
/* 3- Display refresh*/
startMillis = millis(); /* Start record initial time for display refresh */
}
void loop()
{
/* 1- Blynk Server and Wifi Connection */
Blynk.run(); /* allow the communication between Blynk server and Node MCU*/
timer.run(); /* allow the Blynk timer to keep counting */
/* Sun Path Database */
//January First
if(month() == 1 && hour()==7) { angle = 75.90;} if(month() == 1 && hour()==8) { angle = 60.90;}
if(month() == 1 && hour()==9) { angle = 45.90;} if(month() == 1 && hour()==10){ angle = 30.90;}
if(month() == 1 && hour()==11){ angle = 15.90;} if(month() == 1 && hour()==12){ angle = 0.90;}
if(month() == 1 && hour()==13){ angle = -14.10;} if(month() == 1 && hour()==14){ angle = -29.10;}
if(month() == 1 && hour()==15){ angle = -44.10;} if(month() == 1 && hour()==16){ angle = -59.10;}
if(month() == 1 && hour()==17){ angle = -74.10;}
//February First
if(month() == 2 && hour()==7) { angle = 78.55;} if(month() == 2 && hour()==8) { angle = 63.55;}
if(month() == 2 && hour()==9) { angle = 48.55;} if(month() == 2 && hour()==10){ angle = 33.55;}
if(month() == 2 && hour()==11){ angle = 18.55;} if(month() == 2 && hour()==12){ angle = 3.55;}
if(month() == 2 && hour()==13){ angle = -11.45;} if(month() == 2 && hour()==14){ angle = -26.45;}
if(month() == 2 && hour()==15){ angle = -41.45;} if(month() == 2 && hour()==16){ angle = -56.45;}
if(month() == 2 && hour()==17){ angle = -71.45;}
//March First
if(month() == 3 && hour()==7) { angle = 78.25;} if(month() == 3 && hour()==8) { angle = 63.25;}
if(month() == 3 && hour()==9) { angle = 48.25;} if(month() == 3 && hour()==10){ angle = 33.25;}
if(month() == 3 && hour()==11){ angle = 18.25;} if(month() == 3 && hour()==12){ angle = 3.25;}
if(month() == 3 && hour()==13){ angle = -11.75;} if(month() == 3 && hour()==14){ angle = -26.75;}
if(month() == 3 && hour()==15){ angle = -41.75;} if(month() == 3 && hour()==16){ angle = -56.75;}
if(month() == 3 && hour()==17){ angle = -71.75;}
//April First
if(month() == 4 && hour()==7) { angle = 76.03;} if(month() == 4 && hour()==8) { angle = 61.03;}
if(month() == 4 && hour()==9) { angle = 46.03;} if(month() == 4 && hour()==10){ angle = 31.03;}
if(month() == 4 && hour()==11){ angle = 16.03;} if(month() == 4 && hour()==12){ angle = 1.03;}
if(month() == 4 && hour()==13){ angle = -13.97;} if(month() == 4 && hour()==14){ angle = -28.97;}
if(month() == 4 && hour()==15){ angle = -43.97;} if(month() == 4 && hour()==16){ angle = -58.97;}
if(month() == 4 && hour()==17){ angle = -73.97;}
//May First
if(month() == 5 && hour()==7) { angle = 74.25;} if(month() == 5 && hour()==8) { angle = 59.25;}
if(month() == 5 && hour()==9) { angle = 44.25;} if(month() == 5 && hour()==10){ angle = 29.25;}
if(month() == 5 && hour()==11){ angle = 14.25;} if(month() == 5 && hour()==12){ angle = -0.75;}
if(month() == 5 && hour()==13){ angle = -15.75;} if(month() == 5 && hour()==14){ angle = -30.75;}
if(month() == 5 && hour()==15){ angle = -45.75;} if(month() == 5 && hour()==16){ angle = -60.75;}
if(month() == 5 && hour()==17){ angle = -75.75;}
//June First
if(month() == 6 && hour()==7) { angle = 74.42;} if(month() == 6 && hour()==8) { angle = 59.42;}
if(month() == 6 && hour()==9) { angle = 44.42;} if(month() == 6 && hour()==10){ angle = 29.42;}
if(month() == 6 && hour()==11){ angle = 14.42;} if(month() == 6 && hour()==12){ angle = -0.58;}
if(month() == 6 && hour()==13){ angle = -15.58;} if(month() == 6 && hour()==14){ angle = -30.58;}
if(month() == 6 && hour()==15){ angle = -45.58;} if(month() == 6 && hour()==16){ angle = -60.58;}
if(month() == 6 && hour()==17){ angle = -75.58;}
//July First
if(month() == 7 && hour()==7) { angle = 76.00;} if(month() == 7 && hour()==8) { angle = 61.00;}
if(month() == 7 && hour()==9) { angle = 46.00;} if(month() == 7 && hour()==10){ angle = 31.00;}
if(month() == 7 && hour()==11){ angle = 16.00;} if(month() == 7 && hour()==12){ angle = 1.00;}
if(month() == 7 && hour()==13){ angle = -14.00;} if(month() == 7 && hour()==14){ angle = -29.00;}
if(month() == 7 && hour()==15){ angle = -44.00;} if(month() == 7 && hour()==16){ angle = -59.00;}
if(month() == 7 && hour()==17){ angle = -74.00;}
//August First
if(month() == 8 && hour()==7) { angle = 76.66;} if(month() == 8 && hour()==8) { angle = 61.66;}
if(month() == 8 && hour()==9) { angle = 46.66;} if(month() == 8 && hour()==10){ angle = 31.66;}
if(month() == 8 && hour()==11){ angle = 16.66;} if(month() == 8 && hour()==12){ angle = 1.66;}
if(month() == 8 && hour()==13){ angle = -13.34;} if(month() == 8 && hour()==14){ angle = -28.34;}
if(month() == 8 && hour()==15){ angle = -43.34;} if(month() == 8 && hour()==16){ angle = -58.34;}
if(month() == 8 && hour()==17){ angle = -73.34;}
//Semptember First
if(month() == 9 && hour()==7) { angle = 75.03;} if(month() == 9 && hour()==8) { angle = 60.03;}
if(month() == 9 && hour()==9) { angle = 45.03;} if(month() == 9 && hour()==10){ angle = 30.03;}
if(month() == 9 && hour()==11){ angle = 15.03;} if(month() == 9 && hour()==12){ angle = 0.03;}
if(month() == 9 && hour()==13){ angle = -14.97;} if(month() == 9 && hour()==14){ angle = -29.97;}
if(month() == 9 && hour()==15){ angle = -44.97;} if(month() == 9 && hour()==16){ angle = -59.97;}
if(month() == 9 && hour()==17){ angle = -74.97;}
//October First
if(month() == 10 && hour()==7) { angle = 72.32;} if(month() == 10 && hour()==8) { angle = 57.32;}
if(month() == 10 && hour()==9) { angle = 42.32;} if(month() == 10 && hour()==10){ angle = 27.32;}
if(month() == 10 && hour()==11){ angle = 12.32;} if(month() == 10 && hour()==12){ angle = -2.68;}
if(month() == 10 && hour()==13){ angle = -17.68;} if(month() == 10 && hour()==14){ angle = -32.68;}
if(month() == 10 && hour()==15){ angle = -47.68;} if(month() == 10 && hour()==16){ angle = -62.68;}
if(month() == 10 && hour()==17){ angle = -77.68;}
//November First
if(month() == 11 && hour()==7) { angle = 70.69;} if(month() == 11 && hour()==8) { angle = 55.69;}
if(month() == 11 && hour()==9) { angle = 40.69;} if(month() == 11 && hour()==10){ angle = 25.69;}
if(month() == 11 && hour()==11){ angle = 10.69;} if(month() == 11 && hour()==12){ angle = -4.31;}
if(month() == 11 && hour()==13){ angle = -19.31;} if(month() == 11 && hour()==14){ angle = -34.31;}
if(month() == 11 && hour()==15){ angle = -49.31;} if(month() == 11 && hour()==16){ angle = -64.31;}
if(month() == 11 && hour()==17){ angle = -79.31;}
//December First
if(month() == 12 && hour()==7) { angle = 72.10;} if(month() == 12 && hour()==8) { angle = 57.10;}
if(month() == 12 && hour()==9) { angle = 42.10;} if(month() == 12 && hour()==10){ angle = 27.10;}
if(month() == 12 && hour()==11){ angle = 12.10;} if(month() == 12 && hour()==12){ angle = -2.90;}
if(month() == 12 && hour()==13){ angle = -17.90;} if(month() == 12 && hour()==14){ angle = -32.90;}
if(month() == 12 && hour()==15){ angle = -47.90;} if(month() == 12 && hour()==16){ angle = -62.90;}
if(month() == 12 && hour()==17){ angle = -77.90;}
/* 2- Display refresh*/
currentMillis = millis(); /* Keep counting time for display refresh */
if((currentMillis - startMillis >= period) && (lockMechanism == 0)) /* For every 1 minute and not locked, run the set of code*/
{
angleAdd = minute()/4; /* Add angle degree for every minute*/
if( hour()<=6 || hour()>=18) // When there is no sunlight, facing the solar panel to horrizontal
{
angle = 0;
angleAdd = 0;
}
angleFinal = 90-((angle +(offsetAngle-75.90)) - angleAdd); // Final angle of the Servo Motor. 0 = Facing East, 180 = Facing West
if(angleFinal <=0)
{angleFinal =0;}
servo.write(angleFinal); /* command Servo motor with the angle value */
Serial.print("Current degree: ");
Serial.println(angleFinal);
String currentTime = String(hour()) + ":" + minute() + ":" + second(); /* Define "currentTime" by combining hour, minute and second */
String currentDate = String(day()) + " " + month() + " " + year(); /* Define "currentDate" by combining day, month, and year */
Serial.print("Current time: "); /* Display values on Serial Monitor */
Serial.print(currentTime);
Serial.print(" ");
Serial.print(currentDate);
Serial.println();
Blynk.virtualWrite(V3,angleFinal); // Send the angle value to Virtual Pin 3 on Blynk App
startMillis = currentMillis; /* Start Recountng Time */
}
}
BLYNK_CONNECTED() /* When Blynk server is connected, initiate Real Time Clock function */
{ rtc.begin(); }
BLYNK_WRITE(V1) // Virtual SWITCH button is defined as V1 of Blynk App. When the button is PRESSED, it will move the tracker to horrizontal
{ if(param.asInt()==1)
{ angleFinal = 90;
servo.write(angleFinal);
lockMechanism = 1;
Serial.print("Current degree: ");
Serial.println(angleFinal);
}
}
BLYNK_WRITE(V2) // Virtual PUSH button is defined as V2 of Blynk App. It is a safety button to activate the automatic rotation
// When the button is PUSHED, it will allows the tracker back to automatic tracking
{ if(param.asInt()==1)
{
lockMechanism = 0;
startMillis = currentMillis + period;
}
}
Für Hilfe bin ich wirklich Dankbar
Gruss
Wolfgang