Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
I
IOT Code Repository Robert Johnson
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
robert.johnson
IOT Code Repository Robert Johnson
Commits
5147deb1
Commit
5147deb1
authored
Jan 11, 2023
by
robert.johnson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Code for IOT Project
parent
3b45426e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
110 additions
and
0 deletions
+110
-0
Code
Code
+110
-0
No files found.
Code
0 → 100644
View file @
5147deb1
#include <Stepper.h>
#include <Wire.h>
#include <SPI.h>
#include <WiFiNINA.h>
#include <ThingSpeak.h>
#include <LiquidCrystal.h>
// initialize the library by associating any needed LCD interface pin
// with the arduino pin number it is connected to
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
int x = 0;
int y = 0;
int LightOn = 1;
int LightOff = 0;
const int stepsPerRevolution = 200;
// Create a Stepper object using the specified pins
Stepper myStepper(stepsPerRevolution, 4, 10, 7, 13);
const char ssid[] = "BT-8GAJC3";
const char pass[] = "M4JYKE6C3DrVYH";
const unsigned long channel_id = 1984932;
const char write_api_key[] = "5L5MP1LB128S79N4";
WiFiClient client;
#define trigPin 8
#define echoPin 9
float duration, distance;
void setup() {
myStepper.setSpeed(150); // Set the speed of the stepper motor
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
Serial.begin(9600);
Serial.print("Connecting to ");
Serial.print(ssid);
WiFi.begin(ssid, pass);
Serial.println();
Serial.println("Connected!");
ThingSpeak.begin(client);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
}
void loop() {
// Write a pulse to the HC-SR04 Trigger Pin
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
// Measure the response from the HC-SR04 Echo Pin
duration = pulseIn(echoPin, HIGH);
// Determine distance from duration
// Use 343 metres per second as speed of sound
distance = (duration / 2) * 0.0343;
// Send results to Serial Monitor
Serial.print("Distance = ");
if (distance >= 400 || distance <= 2) {
Serial.println("Out of range");
}
else {
if (distance > 105bn ) {
y = 0;
ThingSpeak.setField(2, LightOn);
ThingSpeak.writeFields(channel_id, write_api_key);
while(x < 8){
myStepper.step(stepsPerRevolution);
x++;
}
}
// If the sensor value is less than 30, move the stepper motor 5 revolutions backward
else if (distance < 105) {
x = 0;
ThingSpeak.setField(2, LightOff);
ThingSpeak.writeFields(channel_id, write_api_key);
while(y < 5){
myStepper.step(-stepsPerRevolution);
y++;
}
}
}
Serial.print(distance);
Serial.println(" cm");
// Print a message to the LCD.
lcd.clear();
lcd.print(distance);
lcd.print(" cm");
ThingSpeak.setField(1, distance);
ThingSpeak.writeFields(channel_id, write_api_key);
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment