Components and supplies
5k Ohm resistor
neodymiom magents
LDR Resistor
JQC-3FF-S-Z
laser level
Apps and platforms
Sqlite
Python IDLE
Project description
Code
Arduino 42 LDR sensors
cpp
to be added later
1//This is the first prototype... about 40 ldrs\ 2//This is input mega 22 through 53 3 4#define ldrPin53 53 5#define ldrPin52 52 6#define ldrPin51 51 7#define ldrPin50 50 8#define ldrPin49 49 9#define ldrPin48 48 10#define ldrPin47 47 11#define ldrPin46 46 12#define ldrPin45 45 13#define ldrPin44 44 14#define ldrPin43 43 15#define ldrPin42 42 16#define ldrPin41 41 17#define ldrPin40 40 18#define ldrPin39 39 19#define ldrPin38 38 20#define ldrPin37 37 21#define ldrPin36 36 22#define ldrPin35 35 23#define ldrPin34 34 24#define ldrPin33 33 25#define ldrPin32 32 26#define ldrPin31 31 27#define ldrPin30 30 28#define ldrPin29 29 29#define ldrPin28 28 30#define ldrPin27 27 31#define ldrPin26 26 32#define ldrPin25 25 33#define ldrPin24 24 34#define ldrPin23 23 35#define ldrPin22 22 36#define relayPin 8 37#define puffPin 9 38/* 39*/ 40boolean ldrstatus53 = 0; boolean ldrstatus52 = 0; boolean ldrstatus51 = 0; boolean ldrstatus50 = 0; boolean ldrstatus49 = 0; boolean ldrstatus48 = 0; 41boolean ldrstatus47 = 0; boolean ldrstatus46 = 0; boolean ldrstatus45 = 0; boolean ldrstatus44 = 0; boolean ldrstatus43 = 0; boolean ldrstatus42 = 0; 42boolean ldrstatus41 = 0; boolean ldrstatus40 = 0; boolean ldrstatus39 = 0; boolean ldrstatus38 = 0; boolean ldrstatus37 = 0; boolean ldrstatus36 = 0; 43boolean ldrstatus35 = 0; boolean ldrstatus34 = 0; boolean ldrstatus33 = 0; boolean ldrstatus32 = 0; boolean ldrstatus31 = 0; boolean ldrstatus30 = 0; 44boolean ldrstatus29 = 0; boolean ldrstatus28 = 0; boolean ldrstatus27 = 0; boolean ldrstatus26 = 0; boolean ldrstatus25 = 0; boolean ldrstatus24 = 0; 45boolean ldrstatus23 = 0; boolean ldrstatus22 = 0; 46 47*/ 48 49 50 51float loc_53 = 181.12; float loc_52 = 179.04; float loc_51 = 176.96; float loc_50 = 174.88; float loc_49 = 172.8; float loc_48 = 170.72; 52float loc_47 = 168.64; float loc_46 = 166.56; float loc_45 = 164.48; float loc_44 = 162.4; float loc_43 = 160.32; float loc_42 = 158.24; 53float loc_41 = 156.16; float loc_40 = 154.04; float loc_39 = 152.00; float loc_38 = 149.92; float loc_37 = 147.84; float loc_36 = 145.76; 54float loc_35 = 143.68; float loc_34 = 141.6; float loc_33 = 139.52; float loc_32 = 137.44; float loc_31 = 135.36; float loc_30 = 133.28; 55float loc_29 = 131.2; float loc_28 = 129.12; float loc_27 = 127.04; float loc_26 = 124.96; float loc_25 = 122.88; float loc_24 = 120.8; 56float loc_23 = 118.72; float loc_22 = 116.64; 57 58// 59int megaInputNumber = 1;// this is not currently used for anything 60 61 62long now_time = 340000 ; // just pick a value 63long old_time = 2000; // must be lower than 340000 64 65 66void setup() 67{ 68 pinMode (ldrPin53, INPUT); pinMode (ldrPin52, INPUT); pinMode (ldrPin51, INPUT); pinMode (ldrPin50, INPUT); pinMode (ldrPin49, INPUT); pinMode (ldrPin48, INPUT); 69 pinMode (ldrPin47, INPUT); pinMode (ldrPin46, INPUT); pinMode (ldrPin45, INPUT); pinMode (ldrPin44, INPUT); pinMode (ldrPin43, INPUT); pinMode (ldrPin42, INPUT); 70 pinMode (ldrPin41, INPUT); pinMode (ldrPin40, INPUT); pinMode (ldrPin39, INPUT); pinMode (ldrPin38, INPUT); pinMode (ldrPin37, INPUT); pinMode (ldrPin36, INPUT); 71 pinMode (ldrPin35, INPUT); pinMode (ldrPin34, INPUT); pinMode (ldrPin33, INPUT); pinMode (ldrPin32, INPUT); pinMode (ldrPin31, INPUT); pinMode (ldrPin30, INPUT); 72 pinMode (ldrPin29, INPUT); pinMode (ldrPin28, INPUT); pinMode (ldrPin27, INPUT); pinMode (ldrPin26, INPUT); pinMode (ldrPin25, INPUT); pinMode (ldrPin24, INPUT); 73 pinMode (ldrPin23, INPUT); pinMode (ldrPin22, INPUT); 74 pinMode (relayPin, OUTPUT); 75 pinMode (puffPin, OUTPUT); //I have included a mechanism for pushing the needle between reading. This is a puff of air. I am working on this now. 76 77 digitalWrite (relayPin, HIGH); /// Laser off HIGH is off 78 digitalWrite (puffPin, HIGH); // perturbation thing 79 Serial.begin(9600); 80 Serial.println("hello world"); 81 numberForPython = 88777; 82} 83/* 84I fussed over the delay and came up with using the delta time from the millis() function. My understanding is that the 85delay() function is fine as long as they do not over lap. But I could not make the delay() work for the 30 minute interval 86I got help from the Arduino Forum with this. 87*/ 88void loop() { 89 numberForPython = 88777 // this is error code If there is no positive signal, then this will go into the database. 90 if (now_time > old_time) { 91 92 93 digitalWrite (relayPin, LOW); // low is on .. green light on turn on the laser 94 //the green light should come on (module JQ3CF- 05vD THIS IS LASER ON 95 96 97 //= == == == == == == == == == == == == == == == == == == == == == = 98 delay (10); 99 ldrstatus53 = digitalRead (ldrPin53); 100 if (ldrstatus53 == 1) { 101 numberForPython = loc_53; 102 megaInputNumber = 53; 103 } 104 //= == == == == == == == == == == == == == == == == == == == == == = 105 delay (10); 106 ldrstatus52 = digitalRead (ldrPin52); 107 if (ldrstatus52 == 1) { 108 numberForPython = loc_52; 109 megaInputNumber = 52; 110 } 111 //= == == == == == == == == == == == == == == == == == == == == == = 112 delay (10); 113 ldrstatus51 = digitalRead (ldrPin51); 114 if (ldrstatus51 == 1) { 115 numberForPython = loc_51; 116 megaInputNumber = 51; 117 } 118 //= == == 119 /* 120There are 40 of these little 'if' statements i took them out to shorten the code. I know that there are better ways to write this 121but I am forced to focus on the object; if it works, I move forward. 122The [delay (10)] seems to be manditory 123There may be two 'yes' LDRs . The second one will kick out the first one. I ignore this and assume that a consistent treatment will 124make this unimportant. If no positive signals are found, 125like the laser is not working, then there should be a default output signal. 88777 in this case 126 */ 127 //= == == == == == == == == == == == == == == == == == == == == == = 128 delay (10); 129 ldrstatus24 = digitalRead (ldrPin24); 130 if (ldrstatus24 == 1) { 131 numberForPython = loc_24; 132 megaInputNumber = 24; 133 } 134 //= == == == == == == == == == == == == == == == == == == == == == = 135 delay (10); 136 ldrstatus23 = digitalRead (ldrPin23); 137 if (ldrstatus23 == 1) { 138 numberForPython = loc_23; 139 megaInputNumber = 23; 140 } 141 //= == == == == == == == == == == xxxxxxxxxxxxxxxxxxxxxxxxxxxx 142 delay (10); 143 ldrstatus22 = digitalRead (ldrPin22); 144 if (ldrstatus22 == 1) { 145 numberForPython = loc_22; 146 megaInputNumber = 22; 147 } 148 //= == == == == == == == == == == == == == == == == == == == == == = 149 delay (500); 150 digitalWrite (puffPin, LOW); //turn on 151 delay (200); // just for a moment 152 digitalWrite (puffPin, HIGH); //then turn back off 153 /* 154 relayPin is 8 155 puffPin is 9 156 157 */ 158 delay(1000); 159 digitalWrite(relayPin, HIGH); //turn off the laser 160 Serial.println (numberForPython); // send only this to Python 161 162/* 163 {println()] sends information out to the serial monitor and that is the platform for software development 164 But to send it to the Python the serial monitor must be off. to start the whole; open the arduino, clock download 165 Then, without openeing the serial monitor, run the python. Everything printed in C++ goes to python and it is easies to 166 not send unnecessay stuff. Add the extra database stuff in Python. So the stream fro the Ardino is just number, number number. 167 And notice that the numbers are hard wired in based upon the particular boolean input. 168 169 170 171*/ 172 now_time = millis(); 173 delay (100); 174 //Serial.println (now_time); //this will also go out to Python; could be useful 175 176 old_time = (now_time + 1800000);// 30000 would be 30 seconds. 1800000 is thirty minutes.. 177 178 } 179 delay (100); //I put in delay() here and there because i want to be nice to the compiler. call it professional courtesy. 180 181 now_time = millis(); //this is the time stamp in milliseconds---- 1000 per second 182}
data to Python to sqlite3
python
to be added later
1import serial #import serial library 2import sqlite3 3import datetime 4import sys 5from random import randint 6python_script = sys.argv[0] 7data_object=serial.Serial("COM7",baudrate=9600 , timeout=3.0) # data_object is the object!! 8################### 9conn = sqlite3.connect ('db_final_final_oct_2023') 10c = conn.cursor() 11db_data = 0 12 13c.execute("CREATE TABLE IF NOT EXISTS data_10_16 (column_one TEXT,column_two REAL,column_three, python_script )") 14##### 15######################### ADJUSTMENT VARIABLE LET' JUST USE A HARD NUMBER LIKE 10 OR 20 OR -10 16 17adjustmentNumber = 0 18 19 20 ########################## 21print ("start Python") 22 23 24while (1==1): 25 unix = (datetime.datetime.now()) 26 27 if (data_object.inWaiting()>0): 28 try: 29 in_data = data_object.readline().decode('ascii') 30 in_data = in_data.encode('utf-8') 31 print (in_data) 32 print (adjustmentNumber) 33 in_data = (in_data + adjustment_number) 34 c.execute("INSERT INTO data_10_16 (column_one,column_two,column_three, python_script) VALUES (?,?,?,?)", 35 ( unix , in_data, adjustmentNumber ,python_script ) ) 36 conn.commit() 37 except: 38 pass 39####end########################### 40 """ 41This is all there is to the Python/Database side of it. The detector array is about 4270 millimeters long and the range of values is much greater than that (magnetic north moves a lot!) 43I account for this by moving the detector array by a specific and careful increment and then add this 44in at the python (Adjustment number) There was quite a bit of fuss to maek this work. 45I want the numbers to go ionto the database as integers so they can be graphed. 46This is all under continual development, but this works. 47The data is collected as a boolean yes/no. This is then turned into a corresponding number and 48that number goies into the database. This is pretty lame as an excuse for quantitative anaysis. 49But for tracking the movement of magnetic north, is is satisfactory at least to a first approximation. 50 51"""
Downloadable files
Arduino wiring
fritzing to .jpg ... cool package
wiring fritzing .jpg
focus on LDRs
The LDR circuits are all the same
simplified mega_bb.jpg
Documentation
Magnetic North project narrative
This is my personal journal for Magnetic north
https://app.box.com/s/mos93yuku6abcpk8q3h52hzg8srxsl6k
magnetic needle
This is tucked away in basment
magnetic needle jpg.jpg
first data
see Data Documentation
very preliminary data for project.png
data discussion
this is preliminary data
data narrative for project.pdf
Comments
Only logged in users can leave comments