Skip to content

Commit 597eb63

Browse files
committed
added arduino code
1 parent 7506dbd commit 597eb63

File tree

3 files changed

+174
-0
lines changed

3 files changed

+174
-0
lines changed

Webpage/index.html

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<!DOCTYPE html>
2+
<html>
3+
4+
<iframe width="450" height="260" style="border: 1px solid #cccccc;" src="https://thingspeak.com/channels/907271/charts/2?bgcolor=%23ffffff&color=%23d62020&dynamic=true&results=60&type=line&update=15"></iframe>
5+
<iframe width="450" height="260" style="border: 1px solid #cccccc;" src="https://thingspeak.com/channels/907271/charts/3?bgcolor=%23ffffff&color=%23d62020&dynamic=true&results=60&type=line&update=15"></iframe>
6+
7+
<body>
8+
<iframe width="450" height="260" style="border: 1px solid #cccccc;" src="https://thingspeak.com/channels/907271/charts/1?bgcolor=%23ffffff&color=%23d62020&dynamic=true&results=60&type=line&update=15"></iframe>
9+
<p>Enter the value of volatge, then click "Submit" to submit the value:</p>
10+
11+
<form id="frm1">
12+
Voltage Value: <input type="text" id="field"><br>
13+
<input type="button" onclick="myFunction()" value="Submit">
14+
</form>
15+
16+
<script>
17+
function myFunction() {
18+
var x = document.getElementById("field").value;
19+
var request = new XMLHttpRequest()
20+
request.open('GET', 'https://api.thingspeak.com/update?api_key=TN4QBLC7FRNECOVT&field1='+x, true)
21+
22+
request.onload = function() {
23+
// Begin accessing JSON data here
24+
}
25+
26+
// Send request
27+
request.send()
28+
}
29+
</script>
30+
31+
</body>
32+
</html>

arduino-code/arduino_mega_code.ino

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
int A = 2;
2+
int B = 3;
3+
int C = 4;
4+
int D = 7;
5+
int E = 8;
6+
int F = 9;
7+
int G = 10;
8+
int H = 12;
9+
int I = 13;
10+
byte binary[] = {0,0,0,0,0,0,0,0,0};
11+
void setup() {
12+
Serial.begin(9600);
13+
pinMode(A0,INPUT);
14+
pinMode(A, INPUT);
15+
pinMode(B, INPUT);
16+
pinMode(C, INPUT);
17+
pinMode(D, INPUT);
18+
pinMode(E, INPUT);
19+
pinMode(F, INPUT);
20+
pinMode(G, INPUT);
21+
pinMode(H, INPUT);
22+
pinMode(I, INPUT);
23+
}
24+
25+
void loop() {
26+
binary[0]=digitalRead(A);
27+
binary[1]=digitalRead(B);
28+
binary[2]=digitalRead(C);
29+
binary[3]=digitalRead(D);
30+
binary[4]=digitalRead(E);
31+
binary[5]=digitalRead(F);
32+
binary[6]=digitalRead(G);
33+
binary[7]=digitalRead(H);
34+
binary[8]=digitalRead(I);
35+
int finalval =0;
36+
finalval =(binary[0]*256)+(binary[1]*128)+(binary[2]*64)+(binary[3]*32)+(binary[4]*16)+(binary[5]*8)+(binary[6]*4)+(binary[7]*2)+(binary[8]*1);
37+
38+
Serial.print(finalval);
39+
//Serial.print(binary[0]);
40+
//Serial.print(binary[1]);
41+
//Serial.print(binary[2]);
42+
//Serial.print(binary[3]);
43+
//Serial.print(binary[4]);
44+
//Serial.print(binary[5]);
45+
//Serial.print(binary[6]);
46+
//Serial.print(binary[7]);
47+
//Serial.print(binary[8]);
48+
delay(1000);
49+
}

arduino-code/nodemcu_code.ino

+93
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
//--------------Electronics-project-hub-------------//
2+
#include <ThingSpeak.h>
3+
#include <ESP8266WiFi.h>
4+
const byte numPins = 9;
5+
#define A D0
6+
#define B D1
7+
#define C D2
8+
#define D D3
9+
#define E D4
10+
#define F D5
11+
#define G D6
12+
#define H D7
13+
#define I D8
14+
15+
16+
const char ssid[] = "123"; // your network SSID (name)
17+
const char pass[] = "12312312"; // your network password
18+
19+
WiFiClient client;
20+
21+
unsigned long counterChannelNumber = 907271; // Channel ID
22+
const char * myCounterReadAPIKey = "QDYCJRVCHZXUDXGX"; // Read API Key
23+
const int FieldNumber1 = 1; // The field you wish to read
24+
const int FieldNumber2 = 2; // The field you wish to read
25+
26+
int answer[]={0,0,0,0,0,0,0,0,0};
27+
void setup()
28+
{
29+
Serial.begin(115200);
30+
WiFi.mode(WIFI_STA);
31+
ThingSpeak.begin(client);
32+
pinMode(A, OUTPUT);
33+
pinMode(B, OUTPUT);
34+
pinMode(C, OUTPUT);
35+
pinMode(D, OUTPUT);
36+
pinMode(E, OUTPUT);
37+
pinMode(F, OUTPUT);
38+
pinMode(G, OUTPUT);
39+
pinMode(H, OUTPUT);
40+
pinMode(I, OUTPUT);
41+
}
42+
43+
void loop()
44+
{ int statusCode;
45+
46+
if (WiFi.status() != WL_CONNECTED)
47+
{
48+
Serial.print("Connecting to ");
49+
Serial.print(ssid);
50+
Serial.println(" ....");
51+
while (WiFi.status() != WL_CONNECTED)
52+
{
53+
WiFi.begin(ssid, pass);
54+
delay(5000);
55+
}
56+
Serial.println("Connected to Wi-Fi Succesfully.");
57+
}
58+
59+
int temp = ThingSpeak.readLongField(counterChannelNumber, FieldNumber1, myCounterReadAPIKey);
60+
statusCode = ThingSpeak.getLastReadStatus();
61+
if (statusCode == 200)
62+
{
63+
Serial.print("Voltage value recieved: ");
64+
Serial.println(temp);
65+
}
66+
else
67+
{
68+
Serial.println("Unable to read channel / No internet connection");
69+
}
70+
int i=0;
71+
while (temp>0)
72+
{
73+
answer[i]=temp%2;
74+
temp=temp/2;
75+
i=i+1;
76+
}
77+
//byte num = temp; // Get num from somewhere
78+
//for (byte i=0; i<numPins; i++) {
79+
//byte state = bitRead(num, i);
80+
//digitalWrite(pins[i], state);
81+
//Serial.print(state);
82+
digitalWrite(A, answer[0]);
83+
digitalWrite(B, answer[1]);
84+
digitalWrite(C, answer[2]);
85+
digitalWrite(D, answer[3]);
86+
digitalWrite(E, answer[4]);
87+
digitalWrite(F, answer[5]);
88+
digitalWrite(G, answer[6]);
89+
digitalWrite(H, answer[7]);
90+
digitalWrite(I, answer[8]);
91+
92+
93+
}

0 commit comments

Comments
 (0)